﻿namespace Hidistro.UI.SaleSystem.Tags
{
    using Hidistro.Core;
    using Hidistro.Membership.Context;
    using Hidistro.Membership.Core.Enums;
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class Common_LoginLink : HyperLink
    {
        protected override void Render(HtmlTextWriter writer)
        {
            if (HiContext.Current.User.UserRole == UserRole.Member)
            {
                base.Text = "退出";
                base.NavigateUrl = Globals.GetSiteUrls().UrlData.FormatUrl("logout");
            }
            else
            {
                string ru = "?ReturnUrl=";
                if (this.Page.Request.FilePath == "/login.aspx")
                {
                    ru += System.Web.HttpUtility.UrlEncode(this.Page.Request.QueryString["ReturnUrl"]);
                }
                else if (this.ReturnUrl == null)
                {
                    if (this.Page.Request.RawUrl.ToLower() == "/index.aspx")
                    {
                        ru += "%2f";
                    }
                    else ru += System.Web.HttpUtility.UrlEncode(this.Page.Request.RawUrl);
                }
                else
                {
                    ru += System.Web.HttpUtility.UrlEncode(this.ReturnUrl);
                }
                base.Text = "登录";
                base.NavigateUrl = Globals.GetSiteUrls().UrlData.FormatUrl("login_clean") + ru;
            }
            base.Render(writer);
        }
        public string ReturnUrl { get; set; }
    }
}

